<template>
    <div class="app-container" style="overflow:scroll">
      <div style="width: 1024px;margin: 0 auto">
    <el-form ref="submitParams" :model="submitParams" :rules="rules"  label-width="80px">

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="处理类型" prop="worktype">
            <el-select style="width: 100%;" v-model="submitParams.worktype" @change="worktypeChange" placeholder="处理类型">
              <el-option
                v-for="dict in dictMap.WORKTYPE"
                :key="dict.value"
                :label="`${dict.value}-${dict.text}`"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="预约处理日期" prop="workdate">
            <el-date-picker v-model="submitParams.workdate" style="width: 100%;" type="date" :picker-options="pickerOptions" value-format="yyyyMMdd" :disabled="disable" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24">
          <el-form-item label="批量付款文件上传" prop="fileName">
            <ht-upload-form-item
              ref="attachmentFormItem"
              actionUrl="/union-back/transactionManage/batchFile/BacthFileUpload/upload"
              v-model="submitParams.fileName"
              @successCallback="successCallback"
              :limit="{
                    fileCount: 1,
                    type: ['csv'],
                  }"
              ></ht-upload-form-item>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
        <div slot="footer" class="dialog-footer" align="center">
          <el-button type="primary" @click="submitForm">提交</el-button>
          <el-button type="primary" @click="refresh">重置</el-button>
        </div>
  </div>
    </div>


</template>

<script>
import { submit } from "@/api/cnaps/bizMng/batchFileUpload";
import { listPageMixin } from "@/libs/listPageMixin";
import BankBranchDialog from "@/views/components/BankBranchDialog";
import { milliSendToDate } from "@/utils/common";

export default {
  name: "batchFileUpload",
  mixins: [listPageMixin],
  components: { BankBranchDialog },
  computed:{
  },
  data() {

    return {
      worktypeList:[
        {
        "code": "0",
        "text": "规定日期处理 ",
        "value": "0",
        "listClass": ""
      },
        {
          "code": "1",
          "text": "立即联机处理",
          "value": "1",
          "listClass": ""
        },
      ],
      pickerOptions:{
        // 日期不能大于当前日期
        disabledDate: (time) => {
          return time.getTime() < new Date().getTime()-60*24*60*1000
        }
      },
      disable: false,
      // 录入参数
      submitParams: {
        worktype:"",
        workdate:"",
        fileName:"",
        fileId:""
      },

      //
      searchFormDictList: [
        "WORKTYPE"
      ],


      rules: {
        worktype:[{required: true,message: "请输入处理类型",trigger: "change"}],
        workdate:[{required: true,message: "请输入预约处理日期",trigger: "change"}],
        fileName:[{required: true,message: "请上传付款文件",trigger: "change"}],
      }
    };
  },
  mounted() {
  },
  methods: {
    successCallback(res) {
      if (res.code === "S") {
        this.$set(this.submitParams, "fileName", res.result.fileOriginName);
        this.$set(this.submitParams, "fileId", res.result.fileId);
      }
    },

    /** 提交按钮 */
    submitForm: function() {
      this.$refs["submitParams"].validate(valid => {
        if (valid) {
          submit(this.submitParams).then(res => {
            if (res.code === "S") {
              this.msgSuccess("提交成功");
              /*this.$alert(`ID: ${res.result}`, "生成文件流水号", {
                confirmButtonText: "确定",
                //刷新一下查询列表 TODO
                callback: (action) => {
                },
              });*/
              this.refresh();
            }
          });
        }
      });
    },
    //点击重置按钮
    refresh(){
      this.resetForm("submitParams");
      this.$refs.attachmentFormItem.clearFile();
      this.disable=false;
    },

    worktypeChange(){
      let worktype = this.submitParams.worktype;
      if(worktype==='1'){
        this.$set(this.submitParams,"workdate",milliSendToDate(new Date()))
        this.disable = true;
      }else{
        this.$set(this.submitParams,"workdate","")
        this.disable = false;
      }
    }



  }
};
</script>
